package com.gzw.scm.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gzw.scm.R;
import com.gzw.scm.bean.DBSQInfo;
import com.gzw.scm.bean.JgInfo;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2017/5/23.
 */

public class WBAdapter extends RecyclerView.Adapter{

    public static interface OnRecyclerViewListener {
        void onItemClick(int position);
    }

    private OnRecyclerViewListener onRecyclerViewListener;

    public void setOnRecyclerViewListener(OnRecyclerViewListener onRecyclerViewListener) {
        this.onRecyclerViewListener = onRecyclerViewListener;
    }

    private List<DBSQInfo> list = new ArrayList<>();
    private String type;
    public WBAdapter(List<DBSQInfo> list,String type) {
        this.list = list;
        this.type = type;
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_wb, null);
        LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        view.setLayoutParams(lp);
        return new PersonViewHolder(view);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int i) {
        final PersonViewHolder holder = (PersonViewHolder) viewHolder;
        holder.position = i;


        if(type.equals("0")){
            Integer jsdsmsl = list.get(i).getAcceptnumber()-list.get(i).getJsnum();
            holder.tv_jgmc.setText("发出部门:"+"        "+list.get(i).getUserDname());
            holder.tv_ysm.setText("已扫描发出数量:"+"        "+list.get(i).getAcceptnumber());
            holder.tv_dsm.setText("待扫描接收数量:"+"        "+jsdsmsl);
        }else{
            Integer fcdsmsl = list.get(i).getBringnumber()-list.get(i).getAcceptnumber();
            holder.tv_jgmc.setText("申请部门:"+"        "+list.get(i).getUserDname());
            holder.tv_ysm.setText("已扫描接收数量:"+"        "+list.get(i).getAcceptnumber());
            holder.tv_dsm.setText("待扫描发出数量:"+"        "+fcdsmsl);
        }
        holder.tv_zt.setText("状态:"+"        ");
        holder.tv_num.setText("申请数量:"+"        "+list.get(i).getBringnumber());
    }

    @Override
    public int getItemCount() {
        return list.size();
    }

    class PersonViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
        public View rootView;
        public TextView tv_jgmc;
        public TextView tv_num;
        public TextView tv_zt;
        public TextView tv_ysm;
        public TextView tv_dsm;


        public int position;

        public PersonViewHolder(View itemView) {
            super(itemView);
            tv_jgmc = (TextView) itemView.findViewById(R.id.tv_jgmc);
            tv_num = (TextView) itemView.findViewById(R.id.tv_num);
            tv_zt = (TextView) itemView.findViewById(R.id.tv_zt);
            tv_zt.setVisibility(View.GONE);
            tv_ysm = (TextView) itemView.findViewById(R.id.tv_ysm);
            tv_dsm = (TextView) itemView.findViewById(R.id.tv_dsm);

            rootView = itemView.findViewById(R.id.ll);
            rootView.setOnClickListener(this);
        }

        @Override
        public void onClick(View v) {
            if (null != onRecyclerViewListener) {
                onRecyclerViewListener.onItemClick(position);
            }
        }

    }



}
